<html>
<head>
	<meta charset="UTF-8">
    <title>Web sockets test</title>
    <script src="jquery-1.8.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var ws;
        function ToggleConnectionClicked() {          
                try {
                    ws = new WebSocket("ws://10.9.146.31:1818/chat");//连接服务器		
					
					ws.onopen = function(event){
						var guid=Math.floor(Math.random()*100);
						log("已经与服务器建立了连接..当前连接状态："+this.readyState);
						$('#guid').html(guid);
						ws.send(guid);
						log("已经发送guid："+guid+" 至WebSocket通讯服务器持久存储！");
						
					};
					ws.onmessage = function(event){
						log("接收到服务器发送的数据："+event.data);
						log("为了演示可手动跳转：<a href='http://www.oseye.net?guid="+event.data+"'>oseye</a>");
						log("或者3秒钟自动跳转....");
						window.setTimeout(function(){location.href="http://www.oseye.net?guid="+event.data},3000);

					};
					ws.onclose = function(event){log("已经与服务器断开连接 当前连接状态："+this.readyState);};
					ws.onerror = function(event){log("WebSocket异常！");};
                } catch (ex) {
                    alert(ex.message);      
				}
        };       

	   function log(msg){
			$('#log').html("<p>"+msg+"</p>"+$('#log').html());
	   }

	   ToggleConnectionClicked();
    </script>
</head>
<body>
	<!--<button id='ToggleConnection' type="button" onclick='ToggleConnectionClicked();'>连接服务器</button><br /><br />
    <button id='ToggleConnection' type="button" onclick='SendData();'>发送我的名字：beston</button><br /><br />
    <button id='ToggleConnection' type="button" onclick='seestate();'>查看状态</button><br /><br />-->
	<div id="guid" style="font-size:50px;"></div>
	<div id="log" style="font-size:12px;"></div>
</body>
</html>